﻿<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.aliyuncs.CommonRequest" %>
<%@page import="com.aliyuncs.CommonResponse" %>
<%@ page import="com.aliyuncs.DefaultAcsClient" %>
<%@ page import="com.aliyuncs.IAcsClient" %>
<%@ page import="com.aliyuncs.http.MethodType" %>
<%@ page import="com.aliyuncs.profile.DefaultProfile" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.Random" %>
<%
    new BaseBean().writeLog("短信验证码开始================");
    //校验数据库中数据和所填写数据是否一致     一致不可提交
    DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tG9LVByVrBT9YDwxvcN", "ADGh5KnEeM4WOV6AU8J1xqXa7Isgl3");
    IAcsClient client1 = new DefaultAcsClient(profile);
    CommonRequest request1 = new CommonRequest();
    request1.setSysMethod(MethodType.POST);
    request1.setSysDomain("dysmsapi.aliyuncs.com");
    request1.setSysVersion("2017-05-25");
    request1.setSysAction("SendSms");
    String yddh = request.getParameter("yddh");
    new BaseBean().writeLog("手机号哈哈哈哈================"+yddh);
    request1.putQueryParameter("PhoneNumbers", yddh);
    request1.putQueryParameter("SignName", "TCL中环");
    request1.putQueryParameter("TemplateCode", "SMS_212555018");
    String str = "0123456789";
    StringBuilder sb = new StringBuilder(4);
    for (int i = 0; i < 4; i++) {
        char ch = str.charAt(new Random().nextInt(str.length()));
        sb.append(ch);
    }
    request1.putQueryParameter("TemplateParam", "{\"code\":\""+sb+"\"}");
    Map<String, String> map = new HashMap<String, String>();
    try {
        CommonResponse responses = client1.getCommonResponse(request1);
        String rstJson = responses.getData();
        net.sf.json.JSONObject resultfg = net.sf.json.JSONObject.fromObject(rstJson.toString());
        String code = resultfg.getString("Code");
        if (code.equals("OK")) {
			RecordSet rs3 = new RecordSet();
			RecordSet rs2 = new RecordSet();
			rs2.executeQuery("select sjh from uf_yzm_jm where sjh='" + yddh + "'");
			String bs="false";
			if (rs2.next()) {
				bs="true";
			}
            Date now4 = new Date();
            SimpleDateFormat sdf6 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date afterDate = new Date(now4.getTime() + 300000);
            //日期、时间
            Date dNow = new Date();
            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat ft1 = new SimpleDateFormat("HH:mm:ss");
            String date = ft.format(dNow);
            String time = ft1.format(dNow);
			if(bs.equals("false")){
				rs2.execute("insert into uf_yzm_jm ("
						+ "sjh,yzm,dbsj,"
						+ "formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime)"
						+ " values('" + yddh + "','" + sb+ "','" + sdf6.format(afterDate)
						+ "','41501','" + "1" + "','0','" + date + "','" + time + "')"
				);
			}

			rs3.executeQuery("update uf_yzm_jm set yzm='"+sb+"',modedatacreatedate='"+date+"',modedatacreatetime='"+time+"',dbsj='"+sdf6.format(afterDate)+"' where sjh='"+yddh+"'");
            map.put("success", "true");
            map.put("msg", "");
        } else {
            map.put("success", "false");
            map.put("msg", resultfg.getString("Message"));
        }
        //String zcmc = request.getParameter("zcmc");
    } catch (Exception e) {
        new BaseBean().writeLog("================短信===" + e);
    }

    new BaseBean().writeLog("================结束");
    out.print(JSONObject.toJSON(map));
%>
